/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2022-10-13
 * Time: 18:48
 */
public class Test1 {
    public static int fun(int []arr,int val){
        int left = 0;
        int right = arr.length-1;
        int mid = left+(right-left)/2;
        if(val < arr[0] || val > arr[arr.length-1]){
            return -1;
        }
        while(true){
            if(arr[mid] > val){
                right = mid;
                mid = (right+left)/2;
            }else if(arr[mid] < val){
                left = mid;
                mid = (right + left)/2;
            }else{
                return mid;
            }
            if(left == right){
                return -1;
            }
        }
    }

    public static void main(String[] args) {
        int[] array = {0,1,2,3,4,5,67,89};
        System.out.println(fun(array,67));
    }
}
